package net.sesami.nhg.ebd.batch.exception;

import net.sesami.nhg.ebd.batch.email.ApplicationEmailer;

import org.apache.log4j.Logger;

public class ApplicationException extends RuntimeException {
	private static final Logger LOGGER = Logger
			.getLogger(ApplicationException.class);
	private ApplicationEmailer applicationEmailer = new ApplicationEmailer();
	private String exceptionMessage;
	private Throwable exception;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ApplicationException(String message) {
		super(message);
		this.exceptionMessage = message;
		this.exception = this;
		LOGGER.error(message);
	}

	public ApplicationException(String message, Throwable e) {
		super(message, e);
		this.exceptionMessage = message;
		this.exception = e;
		LOGGER.error(message, e);
	}

	public void notifyViaEmail() {
		this.applicationEmailer.sendExceptionEmail(this.exceptionMessage,
				this.exception);
	}

	public String getExceptionMessage() {
		return exceptionMessage;
	}

	public void setExceptionMessage(String exceptionMessage) {
		this.exceptionMessage = exceptionMessage;
	}

	public Throwable getException() {
		return exception;
	}

}
